// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using ValidationAspects.Exceptions;
using ValidationAspects.Sdk;

namespace ValidationAspects.Factories
{
	public class NotInRange : NumericValidatorFactoryBase
	{
		public double Minimum { get; set; }
		public double Maximum { get; set; }

		#region Overrides of NumericValidatorFactoryBase
		protected override Action<T, IValidationContext> GetValidateAction<T>(Func<T, double, int> compareFunc)
		{
			return (v, c) => { if (compareFunc(v, Minimum) >= 0 && compareFunc(v, Maximum) <= 0) throw new ValidateNotInRangeException(Minimum, Maximum, v); };
		}

		public override IValidator<T> Create<T>()
		{
			if (Minimum >= Maximum)
				throw new ArgumentOutOfRangeException("Minimum", string.Format("Range minimum must be less than maximum [value:{0}].", Maximum));

			return base.Create<T>();
		}
		#endregion
	}
}